package com.sk.weichat.adapter;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sk.weichat.AppConstant;
import com.sk.weichat.R;
import com.sk.weichat.bean.Friend;
import com.sk.weichat.bean.User;
import com.sk.weichat.bean.message.NewFriendMessage;
import com.sk.weichat.db.InternationalizationHelper;
import com.sk.weichat.db.dao.FriendDao;
import com.sk.weichat.db.dao.NewFriendDao;
import com.sk.weichat.helper.AvatarHelper;
import com.sk.weichat.ui.me.PersonalCenterActivity;
import com.sk.weichat.util.TimeUtils;
import com.sk.weichat.util.ToastUtil;
import com.sk.weichat.util.ViewHolder;

import java.util.List;

public class NewFriendAdapter extends BaseQuickAdapter<NewFriendMessage, BaseViewHolder> {
    private String mLoginUserId;
    private Context mContext;
    private List<NewFriendMessage> mNewFriends;
    private NewFriendActionListener mListener;
    private String huihua = null;
    private String username = null;

    public NewFriendAdapter(String loginUserId, List<NewFriendMessage> newFriends) {
        super(R.layout.row_new_friend, newFriends);
        mNewFriends = newFriends;
        mLoginUserId = loginUserId;
    }

    @Override
    protected void convert(BaseViewHolder helper, NewFriendMessage item) {
        ImageView avatar_img = helper.getView(R.id.avatar_img);
        TextView nick_name_tv = helper.getView(R.id.nick_name_tv);
        TextView des_tv = helper.getView(R.id.des_tv);
        TextView tvTime = helper.getView(R.id.tv_call_msg_time);


        // 设置头像
        AvatarHelper.getInstance().displayAvatar(item.getUserId(), avatar_img, false);
        // 昵称
        nick_name_tv.setText(item.getNickName());
        //发送时间
        tvTime.setText(TimeUtils.getFriendlyTimeDesc(mContext,item.getTimeSend()));
        helper.addOnClickListener(R.id.delete_tv);
        helper.addOnClickListener(R.id.layout_new_friend_item);
        int status = item.getState();
        Log.e("state", "-----" + status);
        username = item.getNickName();
        huihua = item.getContent();
        // 显示好友的状态
        fillFriendState(status, item.getUserId(), des_tv);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    private void fillFriendState(int status, String userId, TextView tvDesc) {
        switch (status) {
            case Friend.STATUS_20:
                tvDesc.setText("");
                break;
            case Friend.STATUS_10:
                tvDesc.setText(InternationalizationHelper.getString("JXFriendObject_WaitPass"));
                break;
            case Friend.STATUS_11:
                // tvDesc.setText(InternationalizationHelper.getString("JXUserInfoVC_Hello"));
                tvDesc.setText(username + mContext.getString(R.string.attention_me));
                break;
            case Friend.STATUS_12:
                tvDesc.setText(InternationalizationHelper.getString("JXFriendObject_Passed"));
                break;
            case Friend.STATUS_13:
                tvDesc.setText(InternationalizationHelper.getString("JXFriendObject_PassGo"));
                break;
            case Friend.STATUS_14:
                tvDesc.setText(huihua);
                break;
            case Friend.STATUS_15:
                tvDesc.setText(huihua);
                break;
            case Friend.STATUS_16:
                tvDesc.setText(InternationalizationHelper.getString("JXAlert_DeleteFirend") + username);
                break;
            case Friend.STATUS_17:
                tvDesc.setText(username + mContext.getString(R.string.delete_me));
                break;
            case Friend.STATUS_18://已拉黑了XXX
                tvDesc.setText("你拉黑了"+username);
                break;
            case Friend.STATUS_19://XXX拉黑了你
                tvDesc.setText(username + "拉黑了你");
                break;
            case Friend.STATUS_21:
                tvDesc.setText(username + mContext.getString(R.string.add_me_as_friend));
                break;
            case Friend.STATUS_22:
                Friend friend = FriendDao.getInstance().getFriend(mLoginUserId, userId);
                if (friend != null && friend.getStatus() == Friend.STATUS_SYSTEM) {
                    tvDesc.setText(mContext.getString(R.string.added_notice_friend) + username);
                } else {
                    tvDesc.setText(mContext.getString(R.string.added_friend) + username);
                }
                break;
            case Friend.STATUS_24:
                tvDesc.setText(username + "把你移出黑名单");
                break;
            case Friend.STATUS_25:
                tvDesc.setText("通过手机联系人加为好友");
                break;
            case Friend.STATUS_26:
                tvDesc.setText(huihua);
                break;

            case Friend.STATUS_27://你取关了XXX，解除好友关系
                tvDesc.setText("你取关了"+username+"，解除好友关系");
                break;

            case Friend.STATUS_28://XXX取关了你，解除好友关系
                tvDesc.setText(username+"取关了你，解除好友关系");
                break;

            case Friend.STATUS_29://你把B移出黑名单
                tvDesc.setText("你把"+username+"移出黑名单");
                break;

            case Friend.STATUS_30://你移粉你，解除好友关系
                tvDesc.setText(username+"移粉你，解除好友关系");
                break;

            case Friend.STATUS_31://你移粉XX，解除好友关系
                tvDesc.setText("你移除"+username+"粉丝，解除好友关系");
                break;
        }
    }

    public interface NewFriendActionListener {
        void removeNewFriendMsg(int position);// 移除单条消息
    }
}
